<?php

namespace app\zyhsmarketing\controller;


use think\Controller;

class Huawei extends Controller
{
    /**
     * 记录 华为营销
     */
    public function save()
    {
        $data = $this->request->param();
        // 华为监测连接
        // HOST + ?taskId=__AID__&taskName=__AID_NAME__&appid=__APP_ID__&appName=__APP_NAME__&channelId=__CHANNEL_ID__&channelName=__CHANNEL_NAME__&groupId=__GROUP_ID__&groupName=__GROUP_NAME__&reqId=__REQUEST_ID__&type=__PROMOTION_TYPE__&oaid=__OAID__&action=__ACTION_TYPE__&timestamp=__TS__&callBack=__CALLBACK__
        try
        {
            $insert = [
                'task_id' => $data['taskId'],
                'appid' => $data['appid'],
                'type' => $data['type'],
                'oaid' => $data['oaid'],
                'ts' => $data['timestamp'],
                'callback' => $data['callBack'],
                'action_type' => $data['action'],
                'extend' => json_encode([
                    'task_name' => $data['taskName'],
                    'app_name' => $data['appName'],
                    'channel_id' => $data['channelId'],
                    'channel_name' => $data['channelName'],
                    'group_id' => $data['groupId'],
                    'group_name' => $data['groupName'],
                    'req_id' => $data['reqId'],
                ], JSON_UNESCAPED_UNICODE),
                'day' => (int)$data['day'],
                'target_type' => (int)($data['target_type'] ?? 0),
                'create_time' => $this->request->time(),
                'end_time' => (int)($data['timestamp'] / 1000) + 86400 * $data['day'],
            ];

            (new \app\zyhsapi\model\marketing\ZyhsHuaweiMarketingData())->insert($insert);
        }
        catch (\Exception $e)
        {
            \think\Log::write(__CLASS__ . ' => ' . __FUNCTION__ . '()异常：' . $e->getMessage() . '失败信息：' . $e->getFile() . ':' . $e->getLine(), 'error', true);
        }
    }
}
